/*     */ package nccloud.framework.web.processor.template;
/*     */ 
/*     */ import java.util.ArrayList;
/*     */ import java.util.HashSet;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import java.util.Set;
/*     */ import nc.vo.ml.NCLangRes4VoTransl;
/*     */ import nccloud.framework.core.env.Locator;
/*     */ import nccloud.framework.core.exception.ExceptionUtils;
/*     */ import nccloud.framework.core.reflect.Constructor;
/*     */ import nccloud.framework.web.convert.pattern.BillCardConvertor;
/*     */ import nccloud.framework.web.convert.pattern.CardAreaInfo;
/*     */ import nccloud.framework.web.convert.pattern.CardPosition;
/*     */ import nccloud.framework.web.ui.config.Area;
/*     */ import nccloud.framework.web.ui.config.ITempletResource;
/*     */ import nccloud.framework.web.ui.config.Item;
/*     */ import nccloud.framework.web.ui.config.PageTemplet;
/*     */ import nccloud.framework.web.ui.config.TempletQueryPara;
/*     */ import nccloud.framework.web.ui.meta.AreaRelation;
/*     */ import nccloud.framework.web.ui.meta.AreaType;
/*     */ import nccloud.framework.web.ui.pattern.billcard.BillCard;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class BillCardConvertProcessor
/*     */ {
/*  36 */   private List<String> areacodes = new ArrayList();
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   private PageTemplet pagetemplet;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public BillCardConvertProcessor() {}
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*  56 */   public BillCardConvertProcessor(List<String> areacodes) { this.areacodes = areacodes; }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*  65 */   public BillCardConvertProcessor(PageTemplet pagetemplet) { this.pagetemplet = pagetemplet; }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public BillCard convert(String pagecode, Object vo) {
/*  76 */     PageTemplet templet = getPagetemplet(null, pagecode);
/*  77 */     if (templet == null) {
/*     */       
/*  79 */       ExceptionUtils.wrapBusinessException(NCLangRes4VoTransl.getNCLangRes()
/*  80 */           .getStrByID("1501003_0", "01501003-0066"));
/*  81 */       return null;
/*     */     } 
/*  83 */     CardAreaInfo[] infos = getAreaInfo(templet, this.areacodes);
/*  84 */     BillCardConvertor convertor = new BillCardConvertor();
/*  85 */     BillCard card = convertor.toBillCard(vo, infos);
/*  86 */     card.setPageid(pagecode);
/*  87 */     card.setTempletid(templet.getOid());
/*  88 */     return card;
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public BillCard convertByTempletid(String templetid, String pagecode, Object vo) {
/* 101 */     PageTemplet templet = getPagetemplet(templetid, pagecode);
/* 102 */     if (templet == null) {
/*     */       
/* 104 */       ExceptionUtils.wrapBusinessException(NCLangRes4VoTransl.getNCLangRes()
/* 105 */           .getStrByID("1501003_0", "01501003-0066"));
/* 106 */       return null;
/*     */     } 
/* 108 */     CardAreaInfo[] infos = getAreaInfo(templet, this.areacodes);
/* 109 */     BillCardConvertor convertor = new BillCardConvertor();
/*     */     
/* 111 */     BillCard card = convertor.toBillCard(vo, infos);
/* 112 */     card.setPageid(templet.getPagecode());
/* 113 */     card.setTempletid(templetid);
/* 114 */     return card;
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public BillCard convertByTempletidAndBodyArea(String templetid, String pagecode, String bodyAreaCode, Object vo) {
/* 129 */     PageTemplet templet = getPagetemplet(templetid, pagecode);
/* 130 */     if (templet == null) {
/*     */       
/* 132 */       ExceptionUtils.wrapBusinessException(NCLangRes4VoTransl.getNCLangRes()
/* 133 */           .getStrByID("1501003_0", "01501003-0066"));
/* 134 */       return null;
/*     */     } 
/*     */     
/* 137 */     CardAreaInfo[] infos = getAreaInfoByBodyAreaCode(templet, bodyAreaCode);
/* 138 */     BillCardConvertor convertor = new BillCardConvertor();
/*     */     
/* 140 */     BillCard card = convertor.toBillCard(vo, infos);
/* 141 */     card.setPageid(templet.getPagecode());
/* 142 */     card.setTempletid(templetid);
/* 143 */     return card;
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public BillCard convertOnlyTemplet(String templetid, Object vo, String[] extBodyCodes) {
/* 157 */     PageTemplet templet = getPagetemplet(templetid, null);
/* 158 */     if (templet == null) {
/*     */       
/* 160 */       ExceptionUtils.wrapBusinessException(NCLangRes4VoTransl.getNCLangRes()
/* 161 */           .getStrByID("1501003_0", "01501003-0066"));
/* 162 */       return null;
/*     */     } 
/* 164 */     CardAreaInfo[] infos = getAreaInfo(templet, this.areacodes);
/*     */     
/* 166 */     String[] head = (String[])getHeadAttrcodes(templet).toArray(new String[0]);
/*     */     
/* 168 */     String[] body = (String[])getBodyAttrcodes(templet, extBodyCodes).toArray(new String[0]);
/* 169 */     BillCardConvertor convertor = new BillCardConvertor();
/* 170 */     convertor.setHeadattrs(head);
/* 171 */     convertor.setBodyattrs(body);
/*     */     
/* 173 */     BillCard card = convertor.toBillCard(vo, infos);
/* 174 */     card.setPageid(templet.getPagecode());
/* 175 */     card.setTempletid(templetid);
/* 176 */     return card;
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public <T> T fromBillCard(BillCard card) {
/* 187 */     if (card.getPageid() == null || "".equals(card.getPageid()))
/*     */     {
/* 189 */       ExceptionUtils.wrapBusinessException(NCLangRes4VoTransl.getNCLangRes()
/* 190 */           .getStrByID("1501001_0", "01501001-0232"));
/*     */     }
/*     */     
/* 193 */     PageTemplet templet = getPagetemplet(card.getTempletid(), card.getPageid());
/* 194 */     if (templet.getClazz() == null)
/*     */     {
/* 196 */       ExceptionUtils.wrapBusinessException(NCLangRes4VoTransl.getNCLangRes()
/* 197 */           .getStrByID("1501001_0", "01501001-0233") + card
/* 198 */           .getPageid() + 
/* 199 */           NCLangRes4VoTransl.getNCLangRes().getStrByID("1501001_0", "01501001-0234"));
/*     */     }
/*     */     
/* 202 */     CardAreaInfo[] infos = getAreaInfo(templet, this.areacodes);
/* 203 */     BillCardConvertor convertor = new BillCardConvertor();
/* 204 */     Class<?> clazz = Constructor.load(templet.getClazz());
/* 205 */     Object bill = convertor.fromBillCard(clazz, card, infos);
/* 206 */     return (T)bill;
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public PageTemplet getPagetemplet(String templetid, String pagecode) {
/* 217 */     if (this.pagetemplet != null) {
/* 218 */       return this.pagetemplet;
/*     */     }
/* 220 */     ITempletResource resourc = (ITempletResource)Locator.find(ITempletResource.class);
/* 221 */     TempletQueryPara para = new TempletQueryPara();
/* 222 */     para.setTemplateid(templetid);
/* 223 */     para.setPagecode(pagecode);
/* 224 */     PageTemplet templet = resourc.query(para);
/* 225 */     this.pagetemplet = templet;
/* 226 */     return templet;
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/* 235 */   public void setPagetemplet(PageTemplet pagetemplet) { this.pagetemplet = pagetemplet; }
/*     */ 
/*     */ 
/*     */   
/*     */   private CardAreaInfo[] getAreaInfo(PageTemplet templet, List<String> codes) {
/* 240 */     List<CardAreaInfo> infoList = new ArrayList<CardAreaInfo>();
/* 241 */     String headcode = templet.getHeadcode();
/* 242 */     CardAreaInfo headinfo = new CardAreaInfo();
/* 243 */     Area headArea = templet.getArea(headcode);
/* 244 */     headinfo.setAreacode(headArea.getCode());
/* 245 */     headinfo.setClazz(Constructor.load(headArea.getClazz()));
/* 246 */     headinfo.setPosition(CardPosition.Head);
/* 247 */     headinfo.setGrandSon(headArea.isGrandSon());
/* 248 */     headinfo.setVometa(headArea.getVometa());
/* 249 */     infoList.add(headinfo);
/*     */     
/* 251 */     if (templet.getTailcode() != null) {
/* 252 */       CardAreaInfo tailinfo = new CardAreaInfo();
/* 253 */       Area tailArea = templet.getArea(headcode);
/* 254 */       if (headArea.getClazz() == null)
/*     */       {
/* 256 */         ExceptionUtils.wrapBusinessException(NCLangRes4VoTransl.getNCLangRes()
/* 257 */             .getStrByID("1501001_0", "01501001-0233") + templet
/* 258 */             .getCode() + 
/* 259 */             NCLangRes4VoTransl.getNCLangRes()
/* 260 */             .getStrByID("1501001_0", "01501001-0235") + tailArea
/* 261 */             .getCode() + 
/* 262 */             NCLangRes4VoTransl.getNCLangRes().getStrByID("1501001_0", "01501001-0236"));
/*     */       }
/*     */       
/* 265 */       tailinfo.setAreacode(tailArea.getCode());
/* 266 */       tailinfo.setClazz(Constructor.load(tailArea.getClazz()));
/* 267 */       tailinfo.setPosition(CardPosition.Tail);
/* 268 */       tailinfo.setVometa(tailArea.getVometa());
/* 269 */       infoList.add(tailinfo);
/*     */     } 
/*     */     
/* 272 */     for (Area area : templet.getAllAreas()) {
/* 273 */       if (area.getAreaType().equals(AreaType.Table) && (
/* 274 */         codes == null || !codes.contains(area.getCode()))) {
/*     */ 
/*     */         
/* 277 */         CardAreaInfo bodyarea = new CardAreaInfo();
/* 278 */         bodyarea.setAreacode(area.getCode());
/* 279 */         if (headArea.getClazz() == null)
/*     */         {
/* 281 */           ExceptionUtils.wrapBusinessException(NCLangRes4VoTransl.getNCLangRes()
/* 282 */               .getStrByID("1501001_0", "01501001-0233") + templet
/* 283 */               .getCode() + 
/* 284 */               NCLangRes4VoTransl.getNCLangRes()
/* 285 */               .getStrByID("1501001_0", "01501001-0235") + area
/* 286 */               .getCode() + 
/* 287 */               NCLangRes4VoTransl.getNCLangRes().getStrByID("1501001_0", "01501001-0236"));
/*     */         }
/*     */         
/* 290 */         bodyarea.setClazz(Constructor.load(area.getClazz()));
/* 291 */         bodyarea.setPosition(CardPosition.Body);
/* 292 */         bodyarea.setVometa(area.getVometa());
/* 293 */         bodyarea.setGrandSon(area.grandson);
/* 294 */         infoList.add(bodyarea);
/*     */       } 
/*     */     } 
/* 297 */     return (CardAreaInfo[])infoList.toArray(new CardAreaInfo[0]);
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   private CardAreaInfo[] getAreaInfoByBodyAreaCode(PageTemplet templet, String code) {
/* 312 */     if (code == null || "".equals(code)) {
/* 313 */       return getAreaInfo(templet, this.areacodes);
/*     */     }
/*     */ 
/*     */     
/* 317 */     List<CardAreaInfo> infoList = new ArrayList<CardAreaInfo>();
/* 318 */     String headcode = templet.getHeadcode();
/* 319 */     CardAreaInfo headinfo = new CardAreaInfo();
/* 320 */     Area headArea = templet.getArea(headcode);
/* 321 */     headinfo.setAreacode(headArea.getCode());
/* 322 */     headinfo.setClazz(Constructor.load(headArea.getClazz()));
/* 323 */     headinfo.setPosition(CardPosition.Head);
/* 324 */     headinfo.setGrandSon(headArea.isGrandSon());
/* 325 */     headinfo.setVometa(headArea.getVometa());
/* 326 */     infoList.add(headinfo);
/*     */     
/* 328 */     if (templet.getTailcode() != null) {
/* 329 */       CardAreaInfo tailinfo = new CardAreaInfo();
/* 330 */       Area tailArea = templet.getArea(headcode);
/* 331 */       if (headArea.getClazz() == null)
/*     */       {
/* 333 */         ExceptionUtils.wrapBusinessException(NCLangRes4VoTransl.getNCLangRes()
/* 334 */             .getStrByID("1501001_0", "01501001-0233") + templet
/* 335 */             .getCode() + 
/* 336 */             NCLangRes4VoTransl.getNCLangRes()
/* 337 */             .getStrByID("1501001_0", "01501001-0235") + tailArea
/* 338 */             .getCode() + 
/* 339 */             NCLangRes4VoTransl.getNCLangRes().getStrByID("1501001_0", "01501001-0236"));
/*     */       }
/*     */       
/* 342 */       tailinfo.setAreacode(tailArea.getCode());
/* 343 */       tailinfo.setClazz(Constructor.load(tailArea.getClazz()));
/* 344 */       tailinfo.setPosition(CardPosition.Tail);
/* 345 */       tailinfo.setVometa(tailArea.getVometa());
/* 346 */       infoList.add(tailinfo);
/*     */     } 
/*     */     
/* 349 */     for (Area area : templet.getAllAreas()) {
/* 350 */       if (area.getAreaType().equals(AreaType.Table) && 
/* 351 */         code.equals(area.getCode())) {
/*     */ 
/*     */         
/* 354 */         CardAreaInfo bodyarea = new CardAreaInfo();
/* 355 */         bodyarea.setAreacode(area.getCode());
/* 356 */         if (headArea.getClazz() == null)
/*     */         {
/* 358 */           ExceptionUtils.wrapBusinessException(NCLangRes4VoTransl.getNCLangRes()
/* 359 */               .getStrByID("1501001_0", "01501001-0233") + templet
/* 360 */               .getCode() + 
/* 361 */               NCLangRes4VoTransl.getNCLangRes()
/* 362 */               .getStrByID("1501001_0", "01501001-0235") + area
/* 363 */               .getCode() + 
/* 364 */               NCLangRes4VoTransl.getNCLangRes().getStrByID("1501001_0", "01501001-0236"));
/*     */         }
/*     */         
/* 367 */         bodyarea.setClazz(Constructor.load(area.getClazz()));
/* 368 */         bodyarea.setPosition(CardPosition.Body);
/* 369 */         bodyarea.setVometa(area.getVometa());
/* 370 */         infoList.add(bodyarea);
/*     */       } 
/*     */     } 
/* 373 */     return (CardAreaInfo[])infoList.toArray(new CardAreaInfo[0]);
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   private Set<String> getBodyAttrcodes(PageTemplet templet, String[] extBodyCodes) {
/* 386 */     if (templet == null) {
/* 387 */       return null;
/*     */     }
/* 389 */     Set<String> set = new HashSet<String>();
/* 390 */     Set<String> keySet = templet.getRelations().keySet();
/* 391 */     for (String key : keySet) {
/* 392 */       Item[] keyitems = templet.getArea(key).getItems();
/* 393 */       for (Item item : keyitems) {
/* 394 */         set.add(item.getCode());
/*     */       }
/* 396 */       String[] tabRelation = ((AreaRelation)templet.getRelations().get(key)).getTabRelation();
/* 397 */       if (tabRelation == null || tabRelation.length == 0) {
/*     */         continue;
/*     */       }
/* 400 */       for (String tab : tabRelation) {
/* 401 */         Item[] items = templet.getArea(tab).getItems();
/* 402 */         for (Item item : items) {
/* 403 */           set.add(item.getCode());
/*     */         }
/*     */       } 
/*     */     } 
/* 407 */     for (String extcode : extBodyCodes) {
/* 408 */       set.add(extcode);
/*     */     }
/* 410 */     return set;
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   private Set<String> getHeadAttrcodes(PageTemplet templet) {
/* 420 */     if (templet == null) {
/* 421 */       return null;
/*     */     }
/* 423 */     Set<String> set = new HashSet<String>();
/* 424 */     Item[] headitems = templet.getArea(templet.getHeadcode()).getItems();
/* 425 */     for (Item item : headitems) {
/* 426 */       set.add(item.getCode());
/*     */     }
/* 428 */     String[] forms = new String[0];
/* 429 */     Map<String, String[]> formRelation = templet.getFormRelation();
/* 430 */     if (formRelation != null && formRelation.size() > 0) {
/* 431 */       forms = (String[])formRelation.get(templet.getHeadcode());
/*     */     }
/* 433 */     for (String form : forms) {
/* 434 */       Item[] items = templet.getArea(form).getItems();
/* 435 */       for (Item item : items) {
/* 436 */         set.add(item.getCode());
/*     */       }
/*     */     } 
/* 439 */     return set;
/*     */   }
/*     */ }


/* Location:              E:\zhuhai_ncc\NCC2111\external\lib\pubplatform_baseLevel-1.jar!/nccloud/framework/web/processor/template/BillCardConvertProcessor.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.0.7
 */